package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.entity.SysDept;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class gjl {

    public static List<SysDept> getadd(List<SysDept> ssell){
        List<SysDept> men =
                ssell.stream()
                .filter(sysDept -> sysDept.getParentId()==0)
                .map(sysDept -> {
                    sysDept.setChildren(new ArrayList<>(getch(sysDept,ssell)));
                return sysDept;
                }).collect(Collectors.toList());
return men;
    }
    public  static List<SysDept> getch(SysDept root,List<SysDept> ssell){
       return ssell.stream().filter(sysDept -> sysDept.getParentId().equals(root.getDeptId()))
               .map(sysDept -> {
                   sysDept.setChildren(new ArrayList<>(getidd(sysDept,ssell)));
             return sysDept;
               }).collect(Collectors.toList());
    }
    public static List<SysDept> getidd(SysDept root,List<SysDept> ssell){
        return ssell.stream().filter(sysDept -> sysDept.getParentId().equals(root.getDeptId()))
                .map(sysDept -> {
                    sysDept.setChildren(new ArrayList<>(getch(sysDept,ssell)));
                    return sysDept;
                }).collect(Collectors.toList());
    }


}
